package com.siao.example.libaray.component.view
{
	import com.siao.component.ComboBox;
	import com.siao.component.Orientation;
	import com.siao.component.scroller.ScrollBar;
	import com.siao.data.ArrayList;
	import com.siao.example.common.ui.Layer;
	import com.siao.example.libaray.component.ui.ListItem;
	import com.siao.mvc.View;
	
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	
	/**
	 * 下拉菜单视图
	 * @author SiaoLeon
	 */
	public class ComponentComboBoxView extends View
	{
		// -------------------------------------------------------------------------------------------------------- 静态常量
		
		// -------------------------------------------------------------------------------------------------------- 静态变量
		
		// -------------------------------------------------------------------------------------------------------- 静态方法
		
		// -------------------------------------------------------------------------------------------------------- 静态函数
		
		// -------------------------------------------------------------------------------------------------------- 属性
		
		// -------------------------------------------------------------------------------------------------------- 变量
		
		private var combobox:ComboBox;
		
		private var txtCount:TextField;
		
		// -------------------------------------------------------------------------------------------------------- 构造
		
		/**
		 * 构造函数
		 */
		public function ComponentComboBoxView()
		{
			super();
			
			//生成垂直滚动条
			var backgroundV:Sprite = new Sprite();
			backgroundV.graphics.beginFill(0X000000, 0.8);
			backgroundV.graphics.drawRect(0, 0, 12, 100);
			backgroundV.graphics.endFill();
			
			var dragV:Sprite = new Sprite();
			dragV.graphics.beginFill(0XFF0000, 1);
			dragV.graphics.drawRect(0, 0, 20, 40);
			dragV.graphics.endFill();
			
			var prevV:Sprite = new Sprite();
			prevV.graphics.beginFill(0XFF0000, 0.8);
			prevV.graphics.drawRect(0, 0, 20, 20);
			prevV.graphics.endFill();
			
			var nextV:Sprite = new Sprite();
			nextV.graphics.beginFill(0XFF0000, 0.8);
			nextV.graphics.drawRect(0, 0, 20, 20);
			nextV.graphics.endFill();
			
			var vScrollBar:ScrollBar = new ScrollBar(Orientation.VERTICAL, backgroundV, dragV, prevV, nextV);
			
			var background:Sprite = new Sprite();
			background.graphics.beginFill(0X0FF00F, 0.4);
			background.graphics.drawRect(0, 0, 200, 400);
			background.graphics.endFill();
			
			this.txtCount = new TextField();
			this.txtCount.autoSize = TextFieldAutoSize.LEFT;
			this.txtCount.border = true;
			
			var data:ArrayList = new ArrayList();
			
			for (var i:int = 0; i < 10; i++)
			{
				data.add(i);
			}
			
			this.combobox = new ComboBox();
			this.combobox.addEventListener(Event.SELECT, onSelect);
			this.combobox.x = 20;
			this.combobox.y = 80;
			this.combobox.width = 100;
			this.combobox.height = 30;
			this.combobox.draw(0X000000, 0.2);
			this.combobox.rowSpacing = 20;
			this.combobox.scrollBar = vScrollBar;
			this.combobox.listBackground = background;
			this.combobox.bind(ListItem, data);
			this.combobox.addChild(this.txtCount);
		}
		
		// -------------------------------------------------------------------------------------------------------- 方法
		
		override public function onAdd():void
		{
			Layer.instance.content.addChild(this.combobox);
		
		}
		
		override public function onRemove():void
		{
			Layer.instance.content.removeChild(this.combobox);
		}
		
		// -------------------------------------------------------------------------------------------------------- 函数
		
		private function onSelect(event:Event):void
		{
			this.txtCount.text = this.combobox.selected;
		}
	
	}
}
